package com.huoyun.common.service;

import java.util.List;

import com.huoyun.base.bean.Page;
import com.huoyun.cargo.model.ContactCarModel;
import com.huoyun.common.bean.BidInfo;
import com.huoyun.common.bean.BidInfoItem;
import com.huoyun.common.dao.BidInfoDao;
import com.huoyun.common.service.evt.GetBidInfoByCarIdEvt;
import com.huoyun.common.service.evt.GetBidInfoByGoodsIdEvt;
import com.huoyun.common.service.evt.GetBidInfoItemEvt;
import com.huoyun.order.bean.Order;

public class BidInfoServiceImpl implements BidInfoService{
	BidInfoDao bidInfoDao;
	@Override
	public List<BidInfo> getEntryByCarId(long carId) {
		// TODO Auto-generated method stub
		return bidInfoDao.getEntryByCarId(carId);
	}

	@Override
	public List<BidInfo> getEntryByGoodsId(long goodsId) {
		// TODO Auto-generated method stub
		return bidInfoDao.getEntryByGoodsId(goodsId);
	}

	@Override
	public void saveBidInfo(BidInfo bidInfo) {
		// TODO Auto-generated method stub
		bidInfoDao.saveCarDriver(bidInfo);
	}

	public BidInfoDao getBidInfoDao() {
		return bidInfoDao;
	}

	public void setBidInfoDao(BidInfoDao bidInfoDao) {
		this.bidInfoDao = bidInfoDao;
	}

	@Override
	public int getCountByCarId(long carId) {
		// TODO Auto-generated method stub
		return bidInfoDao.getCountByCarId(carId);
	}

	@Override
	public int getCountByGoodsId(long goodsId) {
		// TODO Auto-generated method stub
		return bidInfoDao.getCountByGoodsId(goodsId);
	}
	
	public List<ContactCarModel> getContactCarsByGoodsId(long goodsId) {
		return bidInfoDao.getContactCarsByGoodsId(goodsId);
	}

	@Override
	public BidInfo getEntryById(long bidId) {
		// TODO Auto-generated method stub
		return bidInfoDao.getEntryById(bidId);
	}

	@Override
	public Order GenerateOrderByBidId(long bidId) {
		// TODO Auto-generated method stub
		return bidInfoDao.GenerateOrderByBidId(bidId);
	}

	@Override
	public void updateSuccess(long bidId,int success) {
		// TODO Auto-generated method stub
		bidInfoDao.updateSuccess(bidId,success);
	}

	@Override
	public List<ContactCarModel> getSelectedCar(long goodsId, int isSuccess) {
		// TODO Auto-generated method stub
		return bidInfoDao.getSelectedCar(goodsId, isSuccess);
	}
	public ContactCarModel getContactCarByBidId(long bidId){
		// TODO Auto-generated method stub
		return bidInfoDao.getContactCarByBidId(bidId);
	}

	@Override
	public List<Order> GenerateOrdersByGoodsId(long goodsId) {
		// TODO Auto-generated method stub
		return bidInfoDao.GenerateOrdersByGoodsId(goodsId);
	}
	
	public List<BidInfo> getBidInfoListByUserId(long userId) {
		return bidInfoDao.getBidInfoListByUserId(userId);
	}
	
	@Override
	/**
	 * 分页版 根据用户状态和用户名查询BidInfoItem
	 * @param getBidInfoItemEvt
	 * @return
	 * @author 杨阳
	 */
	
	public Page queryBidInfoItemByStatusForUser(GetBidInfoItemEvt getBidInfoItemEvt) {
		com.huoyun.common.dao.evt.GetBidInfoItemEvt evt=new com.huoyun.common.dao.evt.GetBidInfoItemEvt();
		evt.setPageCount(getBidInfoItemEvt.getPageCount());
		evt.setPageNo(getBidInfoItemEvt.getPageNo());
		evt.setUserId(getBidInfoItemEvt.getUserId());
		evt.setStatus(getBidInfoItemEvt.getStatus());
		
		Page page=new Page();
		page.setPageCount(evt.getPageCount());
		page.setPageNo(evt.getPageNo());
		page.setTotalRecord(bidInfoDao.getBidInfoItemByStatusForUserCount(evt));
		page.setObjectList(bidInfoDao.queryBidInfoItemByStatusForUser(evt));
		return page;
	}
	
	@Override
	
	public List<BidInfoItem> getBidInfoItemByStatusForUser(long userId,int status){
		return bidInfoDao.getBidInfoItemByStatusForUser(userId, status);
	}
	
	@Override
	public void deleteBidInfoById(long bidInfoId) {
		bidInfoDao.deleteBidInfoById(bidInfoId);
	}

	@Override
	public void updateBidInfoByBidInfo(BidInfo bidInfo) {
		// TODO Auto-generated method stub
		bidInfoDao.updateBidInfoByBidInfo(bidInfo);
	}
	
	/**
	 * 根据车辆id查询应标数
	 * @param getBidInfoByCarIdEvt 查询参数
	 * @return 应标总数
	 */
	@Override
	public int getBidCountByCarId(GetBidInfoByCarIdEvt getBidInfoByCarIdEvt)
	{
		com.huoyun.common.dao.evt.GetBidInfoByCarIdEvt evt = new com.huoyun.common.dao.evt.GetBidInfoByCarIdEvt();
		evt.setCarId(getBidInfoByCarIdEvt.getCarId());
		evt.setType(getBidInfoByCarIdEvt.getType());
		evt.setStatus(getBidInfoByCarIdEvt.getStatus());
		
		return bidInfoDao.getBidCountByCarId(evt);
	}
	
    /**
     * 根据车辆id查询应标列表
     * @param getBidInfoByCarIdEvt 查询参数
     * @return 应标列表
     */
	@Override
	public Page getBidInfoByCarId(GetBidInfoByCarIdEvt getBidInfoByCarIdEvt)
	{
		com.huoyun.common.dao.evt.GetBidInfoByCarIdEvt evt = new com.huoyun.common.dao.evt.GetBidInfoByCarIdEvt();
		evt.setCarId(getBidInfoByCarIdEvt.getCarId());
		evt.setType(getBidInfoByCarIdEvt.getType());
		evt.setStatus(getBidInfoByCarIdEvt.getStatus());
		evt.setPageCount(getBidInfoByCarIdEvt.getPageCount());
		evt.setPageNo(getBidInfoByCarIdEvt.getPageNo());
		
		int totleRecord = bidInfoDao.getBidCountByCarId(evt);
		
		Page page = new Page();
		page.setPageNo(getBidInfoByCarIdEvt.getPageNo());
		page.setPageCount(getBidInfoByCarIdEvt.getPageCount());
		
		//设置总记录数
		page.setTotalRecord(totleRecord);
		
		//设置显示的记录列表
		page.setObjectList(bidInfoDao.getBidInfoByCarId(evt));
		
		return page;
	}
	
	/**
	 * 根据货物id查询应标数
	 * @param getBidInfoByGoodsIdEvt 查询参数
	 * @return 应标数
	 */
	@Override
	public int getBidCountByGoodsId(GetBidInfoByGoodsIdEvt getBidInfoByGoodsIdEvt)
	{
		com.huoyun.common.dao.evt.GetBidInfoByGoodsIdEvt evt = new com.huoyun.common.dao.evt.GetBidInfoByGoodsIdEvt();
		evt.setGoodsId(getBidInfoByGoodsIdEvt.getGoodsId());
		evt.setType(getBidInfoByGoodsIdEvt.getType());
		evt.setStatus(getBidInfoByGoodsIdEvt.getStatus());
		
		return bidInfoDao.getBidCountByGoodsId(evt);
	}
	
	/**
	 * 根据货物id查询应标列表
	 * @param getBidInfoByGoodsIdEvt 查询参数
	 * @return 应标列表
	 */
	@Override
	public Page getBidInfoByGoodsId(GetBidInfoByGoodsIdEvt getBidInfoByGoodsIdEvt)
	{
		com.huoyun.common.dao.evt.GetBidInfoByGoodsIdEvt evt = new com.huoyun.common.dao.evt.GetBidInfoByGoodsIdEvt();
		evt.setGoodsId(getBidInfoByGoodsIdEvt.getGoodsId());
		evt.setType(getBidInfoByGoodsIdEvt.getType());
		evt.setStatus(getBidInfoByGoodsIdEvt.getStatus());
		evt.setPageCount(getBidInfoByGoodsIdEvt.getPageCount());
		evt.setPageNo(getBidInfoByGoodsIdEvt.getPageNo());
		
		int totleRecord = bidInfoDao.getBidCountByGoodsId(evt);
		
		Page page = new Page();
		page.setPageNo(getBidInfoByGoodsIdEvt.getPageNo());
		page.setPageCount(getBidInfoByGoodsIdEvt.getPageCount());
		
		//设置总记录数
		page.setTotalRecord(totleRecord);
		
		//设置显示的记录列表
		page.setObjectList(bidInfoDao.getBidInfoByGoodsId(evt));
		
		return page;
	}


	
}
